{extend name="public/base" /}
{block name="pjax_container"}
<?php
    $titleTypeName = '固定积分编辑/添加';
?>
<style>
    tr>th,
    td {
        text-align: center;
    }

    .btn-group-xs>.btn,
    .btn-xs {
        padding: 5px;
        margin: 0 5px;
    }

    .tab-content{
        border-bottom:none;
    }

    .content-header>.breadcrumb>li {
        color: #999;
    }

    .content-header>.breadcrumb>.active {
        color: #666;
    }

    .content-header {
        height: 51px;

    }

    .btn-primary {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 5px 10px;
    }

    .box-primary {
        border-top-color: #ecf0f5 !important;
        border-top-width: 16px;

    }

    .btn-primary:hover {
        background-color: #1890FF;
        color: #fff;
        border: none;
        opacity: .9;
        border-radius: 6px !important;
    }

    .delete-one {
        background-color: ff4141 !important;
        margin-left: 15px;
        border-radius: 6px;
    }

    .sreachs {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
    }

    .type_explode {
        color: #fff;
        background-color: #d9534f;
        border-radius: 6px;
        border: none;
    }
    .nav-tabs-custom{
        margin-top: 16px;
    }


/* 颜学军弹窗部分样式需用 */
    .form-control {
        border-radius: 6px;
    }

    .table-body {
        width: 540px;
        height: 462px;
        border-radius: 6px;
        background-color: #eee;
    }

    .table-left {
        margin-right: 2%;
        width: 49%;
        height: 100%;
        float: left;
        border: 1px solid #eee;
        background-color: #fff;
    }

    .table-right,
    .table-right2 {
        width: 49%;
        height: 100%;
        border: 1px solid #eee;
        float: left;
        padding-top: 10px;
        background-color: #fff;
    }


</style>
<section class="content-header">
    <ol class="breadcrumb">
        <li>积分管理</li>
        <li>固定积分配置</li>
        <li class="active">{$titleTypeName}</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal layui-form" method="POST" action="/{$Think.MODULE_NAME}/{$Think.CONTROLLER_NAME}/{$Think.ACTION_NAME}" onsubmit="return false" >
                <input type="hidden" name="id" value="{$info.id|default=0}" />
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm" style="padding:10px 2px;"><i class="fa fa-list"></i> 返回</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab1">
                            {include file="form/input" title="名称" name="name"/}
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分类:</label>
                                <div class="col-sm-4">
                                    <input type="text" style="border-radius: 6px;" class="form-control cate_id_name" name="cate_id_name" {if condition="isset($info.cate_id)" } disabled {/if} value="{$info.p_name??''}" placeholder="选择分类" autocomplete="off" >
                                    <input type="hidden" class="cate_id" name="cate_id" value="{$info.cate_id??''}">
                                </div>
                            </div>
                            {include file="form/input" title="固定积分得分" name="integral"/}
                            {include file="form/input_textarea" title="备注" name="desc"/}                            
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="col-sm-2"></div>
                        <div class="col-sm-4">
                            <div class="btn-group pull-right">
                                <button type="submit" class="btn btn-info pull-right submits" data-loading-text="&lt;i class='fa fa-spinner fa-spin '&gt;&lt;/i&gt; 提交">提交</button>
                            </div>
                        </div>
                    </div>

                </div>
            </form>
        </div>
    </div>
</section>
<script type="application/javascript">
    $(document).ready(function () {
        /*ajax页面加载icheck，有该控件的页面才需要*/
        $(".select2").select2({language:"zh-CN"});

    })
    $('.minimal').on('click',function () {
        var type = $(this).val();
        if (type == 1) {
            $('.check').show();
        } else if (type == 0) {
            $('.check').hide();
        }

    });
</script>

<!-- 监听是否为终极分类 -->
<script>
layui.use('form', function(){
  var form = layui.form;
  form.render(); 
  //各种基于事件的操作，下面会有进一步介绍
});
</script>


<!-- 弹框样式引入 -->
<link rel="stylesheet" href="__STATIC__/global/an_tree_css/an_tree_css.css">
<!-- Modal 弹出层重写 部门单选  id="myModal_single"-->
<div class="modal fade" id="myModal_department_single" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width:543px;height: 635px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">分类选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left" style="width:513px;">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                    style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body" style="width: 513px">
                        <div class="table-left" style="width: 100%;">
                            <div class="an_tree search_hide">

                            </div>
                            <div class="search_show" style="display: flex;  flex-direction: column;padding: 20px 10px;">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 部门弹窗操作 部门单选   -->
<script>
    var now_item_name;
    var now_item_id;
    $(".cate_id_name").focus(function () {
        $('#myModal_department_single').modal('show');
        // double_max = $("input[name='double_max']").val();
        now_item_name = $(this);//节点
        now_item_id = $(".cate_id");//节点
        // first_id = $("input[name='first_check_user_id']").val();//id值
        // user_type = 2;
    });

</script>
<!-- 树结构js操作 部门单选  -->
<script>
    $("#myModal_department_single .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_department_single").on("click", ".an_tree_txt", function () {
        $('#myModal_department_single').modal('hide');
        if($(this).attr("data_type") == 0){
            layui.layer.msg("所选分类必须为终极分类！");
        }else{
            now_item_name.val($(this).html());
            now_item_id.val($(this).attr("data_id"));
        }
    });
    $("#myModal_department_single").on("click", ".search_btn", function () {
        var item = $("#myModal_department_single .an_tree_txt");
        var search_name = $("#myModal_department_single input[name='search_user_name']").val();
        $("#myModal_department_single .search_show").html("");
        if(search_name == ""){
            $("#myModal_department_single .search_hide").show();
            $("#myModal_department_single .search_show").removeClass("an_tree");
        }else{
            $("#myModal_department_single .search_hide").hide();
            $("#myModal_department_single .search_show").show();
            var content = "";
            for (let i = 0; i < item.length; i++) {
                var name = item.eq(i).html();
                if (name.indexOf(search_name) != -1) {
                    content += item.eq(i).prop("outerHTML");
                }
                console.log(name);
            }
            $("#myModal_department_single .search_show").append(content)
        }
        
    });
</script>
<!-- 递归填充目录 部门单选  -->
<script>
    var department = "";
     $.ajax({
        type: 'get',
        url: "{:url('base/base_integral_cate')}",
        dataType:"json",
        async: false,
        success: function (data) {
            department = data;
        }
    })
    var an_tree = ergodic(department)
    $("#myModal_department_single .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_type="'+value.type+'" data_pid="' + value.pid + '">' + value.name + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_type="'+value.type+'" data_pid="' + value.pid + '">' + value.name + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>

{/block}
